﻿using System;
using System.Collections;
using System.Collections.Generic;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.stmt;
using SharpSqlAnalyzer.stmt.hive;
using SharpSqlAnalyzer.stmt.mssql;
using SharpSqlAnalyzer.stmt.oracle;
using SharpSqlAnalyzer.util;

namespace SharpSqlAnalyzer
{
	// Token: 0x02000046 RID: 70
	public class TCustomSqlStatement : TParseTreeNode
	{
		// Token: 0x0600004C RID: 76 RVA: 0x00004630 File Offset: 0x00002830
		public void RewriteInit()
		{
			TSourceToken startToken = this.getStartToken();
			if (startToken == null)
			{
				return;
			}
			TSourceToken endToken = this.getEndToken();
			if (endToken == null)
			{
				return;
			}
			TSourceTokenList container = startToken.container;
			if (container == null)
			{
				return;
			}
			int posinlist = startToken.posinlist;
			int posinlist2 = endToken.posinlist;
			for (int i = posinlist; i <= posinlist2; i++)
			{
				TSourceToken tsourceToken = container.get(i);
				tsourceToken.AllowRewrite = true;
				tsourceToken.Changed = false;
			}
		}

		// Token: 0x17000002 RID: 2
		// (get) Token: 0x0600004E RID: 78 RVA: 0x00004698 File Offset: 0x00002898
		// (set) Token: 0x0600004D RID: 77 RVA: 0x0000468F File Offset: 0x0000288F
		public virtual string OracleHint
		{
			get
			{
				return this._oracleHint;
			}
			set
			{
				this._oracleHint = value;
			}
		}

		// Token: 0x17000003 RID: 3
		// (get) Token: 0x06000050 RID: 80 RVA: 0x000046A9 File Offset: 0x000028A9
		// (set) Token: 0x0600004F RID: 79 RVA: 0x000046A0 File Offset: 0x000028A0
		public virtual string Hint
		{
			get
			{
				return this._hint;
			}
			set
			{
				this._hint = value;
			}
		}

		// Token: 0x06000051 RID: 81 RVA: 0x000046B4 File Offset: 0x000028B4
		protected void scanOracleHint(TSourceToken pStartToken)
		{
			if (pStartToken == null)
			{
				return;
			}
			if (this.dbvendor == EDbVendor.dbvoracle || this.dbvendor == EDbVendor.dbvmysql)
			{
				TSourceToken tsourceToken = pStartToken.container.nextsolidtoken(pStartToken.posinlist, 1, true);
				while (tsourceToken != null && (tsourceToken.tokentype == ETokenType.ttsimplecomment || tsourceToken.tokentype == ETokenType.ttbracketedcomment))
				{
					if (tsourceToken.tokentype == ETokenType.ttbracketedcomment && tsourceToken.ToString().StartsWith("/*+", StringComparison.Ordinal))
					{
						tsourceToken.DbObjType = EDbObjectType.oracleHint;
						if (this.OracleHint == null)
						{
							this.OracleHint = tsourceToken.ToString();
						}
						else
						{
							this.OracleHint = this.OracleHint + " " + tsourceToken.ToString();
						}
					}
					if (tsourceToken.tokentype == ETokenType.ttsimplecomment && tsourceToken.ToString().StartsWith("--+", StringComparison.Ordinal))
					{
						tsourceToken.DbObjType = EDbObjectType.oracleHint;
						if (this.OracleHint == null)
						{
							this.OracleHint = tsourceToken.ToString();
						}
						else
						{
							this.OracleHint = this.OracleHint + " " + tsourceToken.ToString();
						}
					}
					tsourceToken = tsourceToken.container.nextsolidtoken(tsourceToken, 1, true);
				}
				this.Hint = this.OracleHint;
			}
		}

		// Token: 0x17000004 RID: 4
		// (get) Token: 0x06000052 RID: 82 RVA: 0x000047D7 File Offset: 0x000029D7
		public List<TObjectName> DatabaseObjects
		{
			get
			{
				return this._DatabaseObjects;
			}
		}

		// Token: 0x06000053 RID: 83 RVA: 0x000047DF File Offset: 0x000029DF
		[Obsolete("use LableName instead")]
		public void setLabelName(TObjectName n)
		{
			this._labelName = n;
		}

		// Token: 0x06000054 RID: 84 RVA: 0x000047E8 File Offset: 0x000029E8
		[Obsolete("use EndLableName instead")]
		public void setEndlabelName(TObjectName n)
		{
			this._endlabelName = n;
		}

		// Token: 0x17000005 RID: 5
		// (get) Token: 0x06000056 RID: 86 RVA: 0x0000480F File Offset: 0x00002A0F
		// (set) Token: 0x06000055 RID: 85 RVA: 0x000047F1 File Offset: 0x000029F1
		public virtual TObjectName LabelName
		{
			get
			{
				return this._labelName;
			}
			set
			{
				this._labelName = value;
				if (this._labelName != null)
				{
					this._labelName.ObjectType = 14;
				}
			}
		}

		// Token: 0x17000006 RID: 6
		// (get) Token: 0x06000058 RID: 88 RVA: 0x00004820 File Offset: 0x00002A20
		// (set) Token: 0x06000057 RID: 87 RVA: 0x00004817 File Offset: 0x00002A17
		public virtual TObjectName EndLabelName
		{
			get
			{
				return this._endlabelName;
			}
			set
			{
				this._endlabelName = value;
			}
		}

		// Token: 0x17000007 RID: 7
		// (get) Token: 0x06000059 RID: 89 RVA: 0x00004828 File Offset: 0x00002A28
		// (set) Token: 0x0600005A RID: 90 RVA: 0x00004830 File Offset: 0x00002A30
		public virtual TTable TargetTable
		{
			get
			{
				return this._targetTable;
			}
			set
			{
				this._targetTable = value;
			}
		}

		// Token: 0x17000008 RID: 8
		// (get) Token: 0x0600005B RID: 91 RVA: 0x00004839 File Offset: 0x00002A39
		public virtual TStatementList Statements
		{
			get
			{
				if (this._statements == null)
				{
					this._statements = new TStatementList();
				}
				return this._statements;
			}
		}

		// Token: 0x17000009 RID: 9
		// (get) Token: 0x0600005D RID: 93 RVA: 0x0000485D File Offset: 0x00002A5D
		// (set) Token: 0x0600005C RID: 92 RVA: 0x00004854 File Offset: 0x00002A54
		public virtual TCTEList CteList
		{
			get
			{
				return this._cteList;
			}
			set
			{
				this._cteList = value;
			}
		}

		// Token: 0x1700000A RID: 10
		// (get) Token: 0x0600005F RID: 95 RVA: 0x0000486E File Offset: 0x00002A6E
		// (set) Token: 0x0600005E RID: 94 RVA: 0x00004865 File Offset: 0x00002A65
		public virtual TResultColumnList ResultColumnList
		{
			get
			{
				return this._resultColumnList;
			}
			set
			{
				this._resultColumnList = value;
			}
		}

		// Token: 0x1700000B RID: 11
		// (get) Token: 0x06000061 RID: 97 RVA: 0x0000487F File Offset: 0x00002A7F
		// (set) Token: 0x06000060 RID: 96 RVA: 0x00004876 File Offset: 0x00002A76
		public virtual TReturningClause ReturningClause
		{
			get
			{
				return this._returningClause;
			}
			set
			{
				this._returningClause = value;
			}
		}

		// Token: 0x1700000C RID: 12
		// (get) Token: 0x06000063 RID: 99 RVA: 0x00004890 File Offset: 0x00002A90
		// (set) Token: 0x06000062 RID: 98 RVA: 0x00004887 File Offset: 0x00002A87
		public virtual TOutputClause OutputClause
		{
			get
			{
				return this._outputClause;
			}
			set
			{
				this._outputClause = value;
			}
		}

		// Token: 0x1700000D RID: 13
		// (get) Token: 0x06000065 RID: 101 RVA: 0x000048A1 File Offset: 0x00002AA1
		// (set) Token: 0x06000064 RID: 100 RVA: 0x00004898 File Offset: 0x00002A98
		public virtual TTopClause TopClause
		{
			get
			{
				return this._topClause;
			}
			set
			{
				this._topClause = value;
			}
		}

		// Token: 0x1700000E RID: 14
		// (get) Token: 0x06000067 RID: 103 RVA: 0x000048B2 File Offset: 0x00002AB2
		// (set) Token: 0x06000066 RID: 102 RVA: 0x000048A9 File Offset: 0x00002AA9
		public virtual TWhereClause WhereClause
		{
			get
			{
				return this._whereClause;
			}
			set
			{
				this._whereClause = value;
			}
		}

		// Token: 0x06000068 RID: 104 RVA: 0x000048BA File Offset: 0x00002ABA
		public virtual TWhereClause addWhereClause(string condition)
		{
			return this._whereClause;
		}

		// Token: 0x06000069 RID: 105 RVA: 0x000048C2 File Offset: 0x00002AC2
		private bool _ableToIncludeCTE(ESqlStatementType sst)
		{
			return sst == ESqlStatementType.sstselect || sst == ESqlStatementType.sstupdate || sst == ESqlStatementType.sstinsert || sst == ESqlStatementType.sstdelete;
		}

		// Token: 0x0600006A RID: 106 RVA: 0x000048D8 File Offset: 0x00002AD8
		protected internal virtual TCTEList searchCTEList()
		{
			TCTEList tctelist = null;
			if (this._cteList != null)
			{
				return this._cteList;
			}
			TCustomSqlStatement parentStmt = this._parentStmt;
			while (parentStmt != null && this._ableToIncludeCTE(parentStmt.sqlstatementtype))
			{
				tctelist = parentStmt._cteList;
				if (tctelist != null)
				{
					break;
				}
				parentStmt = parentStmt._parentStmt;
			}
			return tctelist;
		}

		// Token: 0x1700000F RID: 15
		// (get) Token: 0x0600006B RID: 107 RVA: 0x00004922 File Offset: 0x00002B22
		// (set) Token: 0x0600006C RID: 108 RVA: 0x0000492A File Offset: 0x00002B2A
		public virtual TCustomSqlStatement ParentStmt
		{
			get
			{
				return this._parentStmt;
			}
			set
			{
				if (!this._alreadyAddToParent)
				{
					this._parentStmt = value;
					value.Statements.add(this);
					this._alreadyAddToParent = true;
				}
			}
		}

		// Token: 0x17000010 RID: 16
		// (get) Token: 0x0600006D RID: 109 RVA: 0x00004950 File Offset: 0x00002B50
		public virtual TCustomSqlStatement AncestorStmt
		{
			get
			{
				TCustomSqlStatement tcustomSqlStatement = this;
				while (tcustomSqlStatement.ParentStmt != null)
				{
					tcustomSqlStatement = tcustomSqlStatement.ParentStmt;
				}
				return tcustomSqlStatement;
			}
		}

		// Token: 0x17000011 RID: 17
		// (get) Token: 0x0600006E RID: 110 RVA: 0x00004971 File Offset: 0x00002B71
		public virtual Stack SymbolTable
		{
			get
			{
				if (this._symbolTable == null)
				{
					this._symbolTable = new Stack();
				}
				return this._symbolTable;
			}
		}

		// Token: 0x17000012 RID: 18
		// (get) Token: 0x0600006F RID: 111 RVA: 0x0000498C File Offset: 0x00002B8C
		public virtual int ErrorCount
		{
			get
			{
				return this.fsyntaxerrors.Count;
			}
		}

		// Token: 0x06000070 RID: 112 RVA: 0x0000499C File Offset: 0x00002B9C
		public TCustomSqlStatement(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstunknown;
			this.stmtDummyTag = 0;
			this.sourcetokenlist = new TSourceTokenList();
			this.fsyntaxerrors = new ArrayList();
			this.tables = new TTableList();
			this.joins = new TJoinList();
		}

		// Token: 0x06000071 RID: 113 RVA: 0x000049F5 File Offset: 0x00002BF5
		public virtual EActionOnParseError parseerrormessagehandle(TSyntaxError se)
		{
			this.fsyntaxerrors.Add(se);
			return EActionOnParseError.aopcontinue;
		}

		// Token: 0x06000072 RID: 114 RVA: 0x00004A08 File Offset: 0x00002C08
		public virtual int parsestatement(TCustomSqlStatement pparentsql, bool isparsetreeavailable)
		{
			int num = 0;
			this.isparsed = false;
			if (!isparsetreeavailable)
			{
				num = this.checksyntax(pparentsql);
			}
			if (num == 0)
			{
				this.isparsed = true;
				num = this.doParseStatement(pparentsql);
			}
			else if (this.dbvendor == EDbVendor.dbvsybase && this.rootNode != null && (this.sqlstatementtype == ESqlStatementType.sstmssqlcreateprocedure || this.sqlstatementtype == ESqlStatementType.sstmssqlcreatefunction || this.sqlstatementtype == ESqlStatementType.sstmssqlcreatetrigger))
			{
				this.doParseStatement(pparentsql);
			}
			return num;
		}

		// Token: 0x06000073 RID: 115 RVA: 0x00004A78 File Offset: 0x00002C78
		public virtual bool OracleStatementCanBeSeparatedByBeginEndPair()
		{
			return this.sqlstatementtype == ESqlStatementType.sstplsql_createprocedure || this.sqlstatementtype == ESqlStatementType.sstplsql_createfunction || this.sqlstatementtype == ESqlStatementType.sstplsql_createpackage || this.sqlstatementtype == ESqlStatementType.sstplsql_createtype_placeholder || this.sqlstatementtype == ESqlStatementType.sstoraclecreatepackagebody || this.sqlstatementtype == ESqlStatementType.sstplsql_createtrigger || this.sqlstatementtype == ESqlStatementType.sstplsql_varraytypedef || this.sqlstatementtype == ESqlStatementType.sstplsql_createprocedure || this.sqlstatementtype == ESqlStatementType.sstplsql_execimmestmt || this.sqlstatementtype == ESqlStatementType.sstoraclecreatelibrary;
		}

		// Token: 0x06000074 RID: 116 RVA: 0x00004AF7 File Offset: 0x00002CF7
		public virtual bool isnzplsql()
		{
			return false;
		}

		// Token: 0x06000075 RID: 117 RVA: 0x00004AFA File Offset: 0x00002CFA
		public virtual bool ispgplsql()
		{
			return false;
		}

		// Token: 0x06000076 RID: 118 RVA: 0x00004B00 File Offset: 0x00002D00
		public virtual bool isoracleplsql()
		{
			return this.sqlstatementtype == ESqlStatementType.sst_block_with_label || this.sqlstatementtype == ESqlStatementType.sstplsql_createprocedure || this.sqlstatementtype == ESqlStatementType.sstplsql_createfunction || this.sqlstatementtype == ESqlStatementType.sstplsql_createpackage || this.sqlstatementtype == ESqlStatementType.sstplsql_createtype_placeholder || this.sqlstatementtype == ESqlStatementType.sstoraclecreatepackagebody || this.sqlstatementtype == ESqlStatementType.sstplsql_createtrigger || this.sqlstatementtype == ESqlStatementType.sstplsql_createtypebody || this.sqlstatementtype == ESqlStatementType.sstplsql_tabletypedef || this.sqlstatementtype == ESqlStatementType.sstplsql_varraytypedef || this.sqlstatementtype == ESqlStatementType.sstplsql_createprocedure || this.sqlstatementtype == ESqlStatementType.sstplsql_execimmestmt || this.sqlstatementtype == ESqlStatementType.sstoraclecreatelibrary;
		}

		// Token: 0x06000077 RID: 119 RVA: 0x00004BA9 File Offset: 0x00002DA9
		internal virtual int checksyntax(TCustomSqlStatement psql)
		{
			return this.dochecksyntax(psql);
		}

		// Token: 0x06000078 RID: 120 RVA: 0x00004BB4 File Offset: 0x00002DB4
		protected internal virtual int dochecksyntax(TCustomSqlStatement psql)
		{
			int num = -1;
			this.clear();
			if (this.sourcetokenlist.size() == 0)
			{
				return num;
			}
			if (this.isoracleplsql())
			{
				this.plsqlparser.sql = this;
				this.plsqlparser.sourcetokenlist = this.sourcetokenlist;
				if (this is TCommonStoredProcedureSqlStatement && ((TCommonStoredProcedureSqlStatement)this).Wrapped)
				{
					num = 0;
					this.rootNode = this;
				}
				else
				{
					num = this.plsqlparser.yyparse();
					this.rootNode = this.plsqlparser.rootNode;
				}
			}
			else
			{
				if (this.sqlstatementtype == ESqlStatementType.sstExplain)
				{
					for (int i = 0; i < this.sourcetokenlist.size(); i++)
					{
						TSourceToken tsourceToken = this.sourcetokenlist.get(i);
						if (this.dbvendor == EDbVendor.dbvoracle)
						{
							if (tsourceToken.tokencode == 306)
							{
								tsourceToken.tokencode = 273;
								break;
							}
						}
						else if (this.dbvendor == EDbVendor.dbvredshift && tsourceToken.tokencode == 471)
						{
							tsourceToken.tokencode = 273;
							TSourceToken tsourceToken2 = tsourceToken.nextSolidToken();
							if (tsourceToken2.tokencode == 532)
							{
								tsourceToken2.tokencode = 273;
								break;
							}
							break;
						}
						tsourceToken.tokencode = 273;
					}
				}
				if (this.parser == null && psql != null)
				{
					this.parser = psql.TopStatement.parser;
					this.ParentStmt = psql;
				}
				this.parser.sql = this;
				this.parser.sourcetokenlist = this.sourcetokenlist;
				num = this.parser.yyparse();
				this.rootNode = this.parser.rootNode;
			}
			if (num == 0)
			{
				num = this.fsyntaxerrors.Count;
			}
			if (this.rootNode == null)
			{
				num = -1000;
				this.parseerrormessagehandle(new TSyntaxError("no root node", 0L, 0L, "no_root_node", EErrorType.sperror, -1000));
			}
			return num;
		}

		// Token: 0x06000079 RID: 121 RVA: 0x00004D85 File Offset: 0x00002F85
		public virtual void clearError()
		{
			this.fsyntaxerrors.Clear();
		}

		// Token: 0x0600007A RID: 122 RVA: 0x00004D92 File Offset: 0x00002F92
		internal virtual void clear()
		{
			this.fsyntaxerrors.Clear();
		}

		// Token: 0x0600007B RID: 123 RVA: 0x00004D9F File Offset: 0x00002F9F
		internal virtual void buildsql()
		{
		}

		// Token: 0x0600007C RID: 124 RVA: 0x00004DA4 File Offset: 0x00002FA4
		public virtual int doParseStatement(TCustomSqlStatement psql)
		{
			if (psql != null)
			{
				this.ParentStmt = psql;
			}
			if (base.startToken == null && this.rootNode != null)
			{
				base.startToken = this.rootNode.getStartToken();
			}
			if (base.endToken == null && this.rootNode != null)
			{
				base.endToken = this.rootNode.getEndToken();
			}
			if (this.GSharpSqlParser == null && this.rootNode != null)
			{
				this.GSharpSqlParser = this.rootNode.GSharpSqlParser;
			}
			return 0;
		}

		// Token: 0x0600007D RID: 125 RVA: 0x00004E1F File Offset: 0x0000301F
		internal virtual void addtokentolist(TSourceToken st)
		{
			st.stmt = this;
			this.sourcetokenlist.add(st);
		}

		// Token: 0x0600007E RID: 126 RVA: 0x00004E34 File Offset: 0x00003034
		public virtual TTable analyzeTablename(TObjectName tableName)
		{
			TTable ttable = new TTable();
			ttable.TableType = ETableSource.objectname;
			ttable.startToken = tableName.startToken;
			ttable.endToken = tableName.endToken;
			ttable.TableName = tableName;
			this.tables.addTable(ttable);
			return ttable;
		}

		// Token: 0x0600007F RID: 127 RVA: 0x00004E7C File Offset: 0x0000307C
		protected internal virtual bool isTableACTE(TTable pTable)
		{
			bool result = false;
			TCTEList cteList = this.CteList;
			if (cteList == null)
			{
				for (TCustomSqlStatement parentStmt = this.ParentStmt; parentStmt != null; parentStmt = parentStmt.ParentStmt)
				{
					if (parentStmt.CteList != null)
					{
						cteList = parentStmt.CteList;
						break;
					}
				}
			}
			if (cteList == null)
			{
				return false;
			}
			if (cteList.CTEDict.ContainsKey(TBaseType.getTextWithoutQuoted(pTable.ToString().ToUpper())))
			{
				pTable.CTEName = true;
				pTable.CTE = cteList.CTEDict[TBaseType.getTextWithoutQuoted(pTable.ToString().ToUpper())];
				result = true;
			}
			return result;
		}

		// Token: 0x06000080 RID: 128 RVA: 0x00004F08 File Offset: 0x00003108
		public virtual TTable findTable(ETableEffectType pTableEffectType)
		{
			TTable result = null;
			for (int i = 0; i < this.tables.size(); i++)
			{
				if (this.tables.getTable(i).EffectType == pTableEffectType)
				{
					result = this.tables.getTable(i);
					break;
				}
			}
			return result;
		}

		// Token: 0x06000081 RID: 129 RVA: 0x00004F54 File Offset: 0x00003154
		public virtual void addToTables(TTable pTable)
		{
			this.tables.addTable(pTable);
			if (this.isTableACTE(pTable))
			{
				return;
			}
			if (pTable.TableName == null)
			{
				return;
			}
			if (pTable.TableName.TableToken == null)
			{
				return;
			}
			if ((pTable.TableName.TableString.ToString().Equals("inserted", StringComparison.CurrentCultureIgnoreCase) || pTable.TableName.TableString.ToString().Equals("deleted", StringComparison.CurrentCultureIgnoreCase)) && (this.AncestorStmt.sqlstatementtype == ESqlStatementType.sstmssqlcreatetrigger || this.AncestorStmt.sqlstatementtype == ESqlStatementType.sstmssqlaltertrigger))
			{
				pTable.setLinkTable(true);
				pTable.setLinkTable(this.AncestorStmt.findTable(ETableEffectType.tetTriggerOn));
			}
		}

		// Token: 0x06000082 RID: 130 RVA: 0x00005000 File Offset: 0x00003200
		public virtual TTable analyzeFromTable(TFromTable pfromTable, bool? addToTableList)
		{
			TTable ttable = new TTable();
			ttable.TableType = pfromTable.FromtableType;
			ttable.AliasClause = pfromTable.AliasClause;
			ttable.startToken = pfromTable.startToken;
			ttable.endToken = pfromTable.endToken;
			ttable.TableHintList = pfromTable.TableHintList;
			ttable.TableSample = pfromTable.TableSample;
			ttable.LateralViewList = pfromTable.LateralViewList;
			ttable.TableProperties = pfromTable.TableProperties;
			ttable.PivotedTable = pfromTable.PivotedTable;
			ttable.ParenthesisCount = pfromTable.ParenthesisCount;
			ttable.ParenthesisAfterAliasCount = pfromTable.ParenthesisAfterAliasCount;
			ttable.TableKeyword = pfromTable.TableKeyword;
			ttable.OnlyKeyword = pfromTable.OnlyKeyword;
			ttable.LateralKeyword = pfromTable.LateralKeyword;
			ttable.Flashback = pfromTable.Flashback;
			ttable.PxGranule = pfromTable.PxGranule;
			ttable.IndexHintList = pfromTable.IndexHintList;
			switch (ttable.TableType)
			{
			case ETableSource.objectname:
			{
				bool flag = false;
				if (this.TopStatement.sqlstatementtype == ESqlStatementType.sstmssqlcreatetrigger)
				{
					flag = pfromTable.TableObjectName.ToString().Equals("inserted", StringComparison.CurrentCultureIgnoreCase);
				}
				if (flag)
				{
					ttable.TableName = ((TMssqlCreateTrigger)this.TopStatement).OnTable.TableName;
					ttable.setLinkTable(true);
					ttable.setLinkTable(((TMssqlCreateTrigger)this.TopStatement).OnTable);
				}
				else
				{
					ttable.TableName = pfromTable.TableObjectName;
				}
				TCTEList tctelist = this.searchCTEList();
				if (tctelist != null)
				{
					for (int i = 0; i < tctelist.size(); i++)
					{
						TCTE cte = tctelist.getCTE(i);
						if (cte.TableName.ToString().Equals(ttable.TableName.ToString(), StringComparison.CurrentCultureIgnoreCase))
						{
							ttable.CTEName = true;
							ttable.CTE = cte;
							ttable.CteColomnReferences = cte.ColumnList;
							break;
						}
					}
				}
				break;
			}
			case ETableSource.subquery:
				ttable.Subquery = new TSelectSqlStatement(this.dbvendor);
				ttable.Subquery.rootNode = pfromTable.Subquerynode;
				ttable.Subquery.Location = ESqlClause.elTable;
				ttable.Subquery.doParseStatement(this);
				break;
			case ETableSource.tableExpr:
			{
				ESqlClause plocation = ESqlClause.tableExpr;
				ESqlStatementType esqlStatementType = this.sqlstatementtype;
				ttable.TableExpr = pfromTable.TableExpr;
				ttable.TableExpr.doParse(this, plocation);
				break;
			}
			case ETableSource.function:
			{
				ESqlClause plocation2 = ESqlClause.tableFunction;
				ESqlStatementType esqlStatementType2 = this.sqlstatementtype;
				ttable.FuncCall = pfromTable.FuncCall;
				ttable.FuncCall.doParse(this, plocation2);
				break;
			}
			case ETableSource.rowList:
			{
				ESqlClause plocation3 = ESqlClause.rowList;
				ttable.RowList = pfromTable.RowList;
				ttable.RowList.doParse(this, plocation3);
				break;
			}
			case ETableSource.containsTable:
			{
				ESqlClause plocation4 = ESqlClause.containsTable;
				ESqlStatementType esqlStatementType3 = this.sqlstatementtype;
				ttable.ContainsTable = pfromTable.ContainsTable;
				ttable.ContainsTable.doParse(this, plocation4);
				break;
			}
			case ETableSource.openrowset:
			{
				ESqlClause plocation5 = ESqlClause.openrowset;
				ESqlStatementType esqlStatementType4 = this.sqlstatementtype;
				ttable.OpenRowSet = pfromTable.OpenRowSet;
				ttable.OpenRowSet.doParse(this, plocation5);
				break;
			}
			case ETableSource.openxml:
			{
				ESqlClause plocation6 = ESqlClause.openxml;
				ESqlStatementType esqlStatementType5 = this.sqlstatementtype;
				ttable.OpenXML = pfromTable.OpenXML;
				ttable.OpenXML.doParse(this, plocation6);
				break;
			}
			case ETableSource.opendatasource:
			{
				ESqlClause plocation7 = ESqlClause.opendatasource;
				ESqlStatementType esqlStatementType6 = this.sqlstatementtype;
				ttable.OpenDatasource = pfromTable.OpenDatasource;
				ttable.OpenDatasource.doParse(this, plocation7);
				break;
			}
			case ETableSource.openquery:
			{
				ESqlClause plocation8 = ESqlClause.openquery;
				ESqlStatementType esqlStatementType7 = this.sqlstatementtype;
				ttable.Openquery = pfromTable.OpenQuery;
				ttable.Openquery.doParse(this, plocation8);
				break;
			}
			case ETableSource.datachangeTable:
			{
				ESqlClause plocation9 = ESqlClause.datachangeTable;
				ESqlStatementType esqlStatementType8 = this.sqlstatementtype;
				ttable.DatachangeTable = pfromTable.DatachangeTable;
				ttable.DatachangeTable.doParse(this, plocation9);
				break;
			}
			case ETableSource.xmltable:
				ttable.XmlTable = pfromTable.XmlTable;
				break;
			case ETableSource.informixOuter:
			{
				ESqlClause plocation10 = ESqlClause.outerTable;
				ttable.OuterClause = pfromTable.OuterClause;
				ttable.OuterClause.doParse(this, plocation10);
				break;
			}
			case ETableSource.table_ref_list:
				ttable.FromTableList = pfromTable.FromTableList;
				break;
			case ETableSource.hiveFromQuery:
			{
				THiveFromQuery thiveFromQuery = new THiveFromQuery(EDbVendor.dbvhive);
				thiveFromQuery.rootNode = pfromTable.FromQuerySqlNode;
				thiveFromQuery.doParseStatement(this);
				ttable.HiveFromQuery = thiveFromQuery;
				break;
			}
			case ETableSource.pivoted_table:
			{
				ESqlClause plocation11 = ESqlClause.pivoted_table;
				ttable.PivotedTable.doParse(this, plocation11);
				addToTableList = new bool?(false);
				this._targetTable = ttable;
				break;
			}
			case ETableSource.output_merge:
			{
				TMergeSqlStatement tmergeSqlStatement = new TMergeSqlStatement(EDbVendor.dbvmssql);
				tmergeSqlStatement.rootNode = pfromTable.MergeSqlNode;
				tmergeSqlStatement.doParseStatement(this);
				ttable.OutputMerge = tmergeSqlStatement;
				break;
			}
			case ETableSource.jsontable:
				ttable.JsonTable = pfromTable.JsonTable;
				break;
			}
			ttable.PartitionExtensionClause = pfromTable.PartitionExtensionClause;
			if (addToTableList.Value)
			{
				this.addToTables(ttable);
			}
			if (ttable.TableHintList != null)
			{
				for (int j = 0; j < ttable.TableHintList.Count; j++)
				{
					TTableHint ttableHint = ttable.TableHintList[j];
					ttableHint.OwnerTable = ttable;
					ttableHint.doParse(this, ESqlClause.tableHint);
				}
			}
			if (ttable.AliasClause != null && ttable.AliasClause.ToString().Equals("and", StringComparison.CurrentCultureIgnoreCase))
			{
				TSourceToken startToken = ttable.AliasClause.startToken;
				TSyntaxError se = new TSyntaxError(startToken.ToString(), startToken.lineNo, startToken.columnNo, string.Format("AND keyword can't be table alias", new object[0]), EErrorType.sperror, 10111);
				this.parseerrormessagehandle(se);
			}
			return ttable;
		}

		// Token: 0x06000083 RID: 131 RVA: 0x00005570 File Offset: 0x00003770
		public virtual TJoin analyzeJoin(TJoinExpr pJoinExpr, TJoin pJoin, bool? isSub)
		{
			TJoin tjoin = pJoin;
			TJoinItem tjoinItem = null;
			if (pJoinExpr == null)
			{
				return tjoin;
			}
			if (pJoinExpr.Jointype == EJoinType.nested)
			{
				if (isSub.Value)
				{
					if (tjoin == null)
					{
						tjoin = new TJoin();
						tjoin.startToken = pJoinExpr.startToken;
						tjoin.endToken = pJoinExpr.endToken;
					}
					pJoinExpr.Jointype = pJoinExpr.original_jontype;
					tjoin.Join = this.analyzeJoin(pJoinExpr, null, new bool?(true));
					tjoin.Kind = 3;
					tjoin.Join.AliasClause = pJoinExpr.AliasClause;
					tjoin.Join.WithParen = true;
					tjoin.Join.NestedParen = pJoinExpr.NestedParen;
				}
				else
				{
					if (tjoin == null)
					{
						tjoin = new TJoin();
						tjoin.startToken = pJoinExpr.startToken;
						tjoin.endToken = pJoinExpr.endToken;
					}
					pJoinExpr.Jointype = pJoinExpr.original_jontype;
					tjoin = this.analyzeJoin(pJoinExpr, tjoin, new bool?(false));
					tjoin.AliasClause = pJoinExpr.AliasClause;
					tjoin.WithParen = true;
					tjoin.NestedParen = pJoinExpr.NestedParen;
				}
				return tjoin;
			}
			if (pJoinExpr.LeftOperand.FromtableType != ETableSource.join)
			{
				if (tjoin == null)
				{
					tjoin = new TJoin();
					tjoin.startToken = pJoinExpr.startToken;
					tjoin.endToken = pJoinExpr.endToken;
				}
				TTable ttable = this.analyzeFromTable(pJoinExpr.LeftOperand, new bool?(true));
				ttable.EffectType = ETableEffectType.tetSelect;
				tjoin.Table = ttable;
				tjoin.Kind = 2;
			}
			else
			{
				TJoinExpr joinExpr = pJoinExpr.LeftOperand.JoinExpr;
				if (tjoin != null)
				{
					tjoin = this.analyzeJoin(joinExpr, tjoin, new bool?(true));
				}
				else
				{
					tjoin = this.analyzeJoin(joinExpr, tjoin, isSub);
				}
				tjoin.startToken = pJoinExpr.startToken;
				tjoin.endToken = pJoinExpr.endToken;
			}
			if (pJoinExpr.RightOperand.FromtableType != ETableSource.join)
			{
				if (tjoin != null)
				{
					tjoinItem = new TJoinItem();
					TTable ttable2 = this.analyzeFromTable(pJoinExpr.RightOperand, new bool?(true));
					ttable2.EffectType = ETableEffectType.tetSelect;
					tjoinItem.Table = ttable2;
					tjoinItem.startToken = tjoinItem.Table.startToken;
					tjoinItem.Kind = 2;
					tjoin.JoinItems.addJoinItem(tjoinItem);
				}
			}
			else if (tjoin != null)
			{
				tjoinItem = new TJoinItem();
				tjoinItem.Kind = 3;
				TJoinExpr joinExpr2 = pJoinExpr.RightOperand.JoinExpr;
				tjoinItem.Join = this.analyzeJoin(pJoinExpr.RightOperand.JoinExpr, null, new bool?(false));
				tjoinItem.Join.AliasClause = joinExpr2.AliasClause;
				tjoinItem.startToken = tjoinItem.Join.startToken;
				tjoin.JoinItems.addJoinItem(tjoinItem);
			}
			if (tjoinItem == null)
			{
				return tjoin;
			}
			tjoinItem.JoinType = pJoinExpr.Jointype;
			tjoinItem.JoinHint = pJoinExpr.JoinHint;
			tjoinItem.UsingColumns = pJoinExpr.UsingColumns;
			if (tjoinItem.UsingColumns != null && this.tables.size() > 1)
			{
				for (int i = 0; i < tjoinItem.UsingColumns.size(); i++)
				{
					TObjectName objectName = tjoinItem.UsingColumns.getObjectName(i);
					this.tables.getTable(this.tables.size() - 1).ObjectNameReferences.addObjectName(objectName);
					this.tables.getTable(this.tables.size() - 2).ObjectNameReferences.addObjectName(objectName);
					this.tables.getTable(this.tables.size() - 1).LinkedColumns.addObjectName(objectName);
					objectName.SourceTable = this.tables.getTable(this.tables.size() - 1);
					this.tables.getTable(this.tables.size() - 2).LinkedColumns.addObjectName(objectName);
					objectName.SourceTable = this.tables.getTable(this.tables.size() - 2);
				}
				tjoinItem.endToken = tjoinItem.UsingColumns.endToken;
			}
			tjoinItem.OnCondition = pJoinExpr.OnCondition;
			if (tjoinItem.OnCondition != null)
			{
				tjoinItem.OnCondition.doParse(this, ESqlClause.joinCondition);
				tjoinItem.endToken = tjoinItem.OnCondition.endToken;
			}
			return tjoin;
		}

		// Token: 0x06000084 RID: 132 RVA: 0x00005960 File Offset: 0x00003B60
		public virtual bool locateVariableOrParameter(TObjectName cr)
		{
			bool flag = false;
			if (this.dbvendor != EDbVendor.dbvoracle)
			{
				return false;
			}
			if (cr.ObjectType == 10)
			{
				return true;
			}
			object[] array = this.TopStatement.SymbolTable.ToArray();
			TObjectName tobjectName = null;
			TObjectName tobjectName2 = null;
			for (int i = array.Length - 1; i >= 0; i--)
			{
				TSymbolTableItem tsymbolTableItem = (TSymbolTableItem)array[i];
				if (tsymbolTableItem.Data is TParameterDeclaration)
				{
					tobjectName = ((TParameterDeclaration)tsymbolTableItem.Data).ParameterName;
				}
				else if (tsymbolTableItem.Data is TVarDeclStmt)
				{
					tobjectName = ((TVarDeclStmt)tsymbolTableItem.Data).ElementName;
				}
				else if (tsymbolTableItem.Data is TObjectName)
				{
					tobjectName = (TObjectName)tsymbolTableItem.Data;
				}
				if (tobjectName != null)
				{
					if (cr.ToString().Equals(tobjectName.ToString(), StringComparison.CurrentCultureIgnoreCase))
					{
						flag = true;
						int position = 0;
						while (i < this.tables.size())
						{
							TTable table = this.tables.getTable(position);
							if (table.BaseTable && this.fireOnMetaDatabaseTableColumn(table.PrefixServer, table.PrefixDatabase, table.PrefixSchema, table.Name, cr.ColumnNameOnly))
							{
								flag = false;
								break;
							}
							i++;
						}
						if (flag)
						{
							break;
						}
					}
					else if (cr.ToString().IndexOf(".", StringComparison.Ordinal) > 0)
					{
						if (tsymbolTableItem.Stmt is TPlsqlCreateFunction)
						{
							tobjectName2 = ((TPlsqlCreateFunction)tsymbolTableItem.Stmt).FunctionName;
						}
						else if (tsymbolTableItem.Stmt is TPlsqlCreateProcedure)
						{
							tobjectName2 = ((TPlsqlCreateProcedure)tsymbolTableItem.Stmt).ProcedureName;
						}
						else if (tsymbolTableItem.Stmt is TCommonBlock)
						{
							tobjectName2 = ((TCommonBlock)tsymbolTableItem.Stmt).LabelName;
						}
						if (tobjectName2 != null && cr.ToString().Equals(tobjectName2.ToString() + "." + tobjectName.ToString(), StringComparison.CurrentCultureIgnoreCase))
						{
							flag = true;
						}
						if (flag)
						{
							break;
						}
					}
				}
			}
			if (flag)
			{
				tobjectName.ReferencedObjects.addObjectName(cr);
				cr.ObjectType = 10;
			}
			return flag;
		}

		// Token: 0x06000085 RID: 133 RVA: 0x00005B64 File Offset: 0x00003D64
		internal virtual TCTE findCTEByName(string cteName)
		{
			TCTEList tctelist = this.searchCTEList();
			TCTE result = null;
			if (tctelist != null)
			{
				for (int i = 0; i < tctelist.size(); i++)
				{
					if (tctelist.getCTE(i).TableName.ToString().Equals(cteName, StringComparison.CurrentCultureIgnoreCase))
					{
						result = tctelist.getCTE(i);
						break;
					}
				}
			}
			return result;
		}

		// Token: 0x06000086 RID: 134 RVA: 0x00005BB4 File Offset: 0x00003DB4
		protected internal virtual bool fireOnMetaDatabaseTableColumn(string pServer, string pDatabase, string pSchema, string pTable, string pColumn)
		{
			bool result = false;
			if (this.GSharpSqlParser.MetaDatabase != null)
			{
				result = this.GSharpSqlParser.MetaDatabase.checkColumn(pServer, pDatabase, pSchema, pTable, pColumn);
			}
			return result;
		}

		// Token: 0x17000013 RID: 19
		// (get) Token: 0x06000087 RID: 135 RVA: 0x00005BEC File Offset: 0x00003DEC
		public virtual TTable FirstPhysicalTable
		{
			get
			{
				TTable result = null;
				if (this.tables.size() == 0)
				{
					return null;
				}
				for (int i = 0; i < this.tables.size(); i++)
				{
					if (this.tables.getTable(i).BaseTable)
					{
						result = this.tables.getTable(i);
						break;
					}
				}
				return result;
			}
		}

		// Token: 0x17000014 RID: 20
		// (get) Token: 0x06000088 RID: 136 RVA: 0x00005C43 File Offset: 0x00003E43
		public virtual TObjectNameList OrphanColumns
		{
			get
			{
				if (this._orphanColumns == null)
				{
					this._orphanColumns = new TObjectNameList();
				}
				return this._orphanColumns;
			}
		}

		// Token: 0x06000089 RID: 137 RVA: 0x00005C60 File Offset: 0x00003E60
		protected internal virtual bool linkToFirstTable(TObjectName pColumn, int pCandidateTableCnt)
		{
			bool result = false;
			if (this.tables.size() == 1 || pCandidateTableCnt == 1)
			{
				this.tables.getTable(0).LinkedColumns.addObjectName(pColumn);
				pColumn.SourceTable = this.tables.getTable(0);
				result = true;
			}
			else if (this.tables.size() > 1)
			{
				this.OrphanColumns.addObjectName(pColumn);
			}
			return result;
		}

		// Token: 0x0600008A RID: 138 RVA: 0x00005CCC File Offset: 0x00003ECC
		internal virtual bool isSQLServerInsertedDelete(TObjectName pColumn)
		{
			if ((pColumn.ToString().ToUpper().StartsWith("INSERTED") || pColumn.ToString().ToUpper().StartsWith("DELETED")) && this._targetTable != null)
			{
				this._targetTable.ObjectNameReferences.addObjectName(pColumn);
				pColumn.SourceTable = this._targetTable;
				return true;
			}
			return false;
		}

		// Token: 0x0600008B RID: 139 RVA: 0x00005D30 File Offset: 0x00003F30
		internal virtual bool isOracleNewOldTable(TObjectName pColumn)
		{
			bool result = false;
			if (this.dbvendor != EDbVendor.dbvoracle)
			{
				return false;
			}
			if (!pColumn.Prefixed)
			{
				return false;
			}
			if (pColumn.TableString.Equals(":new", StringComparison.CurrentCultureIgnoreCase) || pColumn.TableString.Equals(":old", StringComparison.CurrentCultureIgnoreCase))
			{
				this.AncestorStmt.tables.getTable(0).LinkedColumns.addObjectName(pColumn);
				pColumn.SourceTable = this.AncestorStmt.tables.getTable(0);
				result = true;
			}
			return result;
		}

		// Token: 0x0600008C RID: 140 RVA: 0x00005DB4 File Offset: 0x00003FB4
		public virtual bool linkColumnToTable(TObjectName pColumn, ESqlClause pLocation)
		{
			bool flag = false;
			bool flag2 = false;
			int num = 0;
			if (pColumn.SourceTable != null)
			{
				return true;
			}
			pColumn.Location = pLocation;
			if (!pColumn.isValidColumnName(this.dbvendor))
			{
				if (pColumn.DbObjectType == EDbObjectType.sequence)
				{
					this.DatabaseObjects.Add(pColumn);
				}
				return false;
			}
			if (this.locateVariableOrParameter(pColumn))
			{
				return false;
			}
			if (this.isOracleNewOldTable(pColumn))
			{
				return true;
			}
			if (this.isSQLServerInsertedDelete(pColumn))
			{
				return true;
			}
			for (int i = 0; i < this.tables.size(); i++)
			{
				TTable table = this.tables.getTable(i);
				if (pColumn.Prefixed)
				{
					flag = pColumn.isPrefixedThisTable(table);
					if (flag && table.TableType == ETableSource.subquery)
					{
						table.Subquery.searchColumnInResultSet(pColumn, true);
					}
					else if (flag && table.CTEName)
					{
						table.CTE.searchColumnInResultSet(this, table, pColumn, true);
					}
				}
				else if (pColumn.ColumnNameOnly.Equals("*", StringComparison.CurrentCultureIgnoreCase))
				{
					flag = true;
					flag2 = true;
				}
				else if (table.BaseTable)
				{
					flag = this.fireOnMetaDatabaseTableColumn(table.PrefixServer, table.PrefixDatabase, table.PrefixSchema, table.Name, pColumn.ColumnNameOnly);
					if (!flag)
					{
						num++;
					}
				}
				else if (table.TableType == ETableSource.subquery)
				{
					if (!table.IncludeColumnAlias)
					{
						flag = table.Subquery.searchColumnInResultSet(pColumn, this.tables.size() == 1);
						if (!flag)
						{
							num++;
						}
					}
				}
				else if (table.CTEName)
				{
					flag = table.CTE.searchColumnInResultSet(this, table, pColumn, this.tables.size() == 1);
					if (!flag)
					{
						num++;
					}
				}
				if (flag)
				{
					table.LinkedColumns.addObjectName(pColumn);
					pColumn.SourceTable = table;
					if (!flag2)
					{
						break;
					}
				}
			}
			if (flag)
			{
				return true;
			}
			bool flag3 = this._parentStmt != null;
			if (flag3 && this.sqlstatementtype == ESqlStatementType.sstselect)
			{
				flag3 = (pColumn.Prefixed || (((TSelectSqlStatement)this).Location != ESqlClause.elTable && !((TSelectSqlStatement)this).QueryOfCTE));
			}
			if (flag3)
			{
				pColumn.searchLevel++;
				flag = this._parentStmt.linkColumnToTable(pColumn, pLocation);
				pColumn.searchLevel--;
			}
			if (!flag && pColumn.searchLevel == 0)
			{
				this.linkToFirstTable(pColumn, num);
			}
			return flag;
		}

		// Token: 0x0600008D RID: 141 RVA: 0x00006010 File Offset: 0x00004210
		[Obsolete("use linkColumnToTable instead")]
		public virtual void linkColumnReferenceToTable(TObjectName cr, ESqlClause plocation)
		{
			if (cr == null)
			{
				return;
			}
			cr.Location = plocation;
			if (cr.ObjectType == 10)
			{
				return;
			}
			if (cr.ObjectType == 2)
			{
				return;
			}
			if (this.dbvendor == EDbVendor.dbvsybase)
			{
				TSourceToken partToken = cr.PartToken;
				if (partToken != null && partToken.tokentype == ETokenType.ttdqstring)
				{
					if (partToken.ToString()[1] >= '0' && partToken.ToString()[1] <= '9')
					{
						return;
					}
					if (partToken.ToString().Length == 2)
					{
						return;
					}
					if (partToken.ToString().Substring(1, partToken.ToString().Length - 1 - 1).Trim().Length == 0)
					{
						return;
					}
				}
			}
			if (cr.PartToken != null && cr.PartToken.tokentype == ETokenType.ttkeyword)
			{
				bool flag = false;
				EDbVendor dbvendor = this.dbvendor;
				if (dbvendor != EDbVendor.dbvmssql)
				{
					if (dbvendor == EDbVendor.dbvsybase)
					{
						flag = keywordChecker.isKeyword(cr.PartToken.ToString(), EDbVendor.dbvsybase, "15.7", true);
					}
				}
				else
				{
					flag = !TLexerMssql.canBeColumnName(cr.PartToken.tokencode);
				}
				if (flag)
				{
					return;
				}
			}
			if (cr.ToString().StartsWith("@", StringComparison.Ordinal))
			{
				cr.ObjectType = -1;
				return;
			}
			if (this.dbvendor == EDbVendor.dbvoracle && (cr.ToString().Equals("rowid", StringComparison.CurrentCultureIgnoreCase) || cr.ToString().Equals("sysdate", StringComparison.CurrentCultureIgnoreCase) || cr.ToString().Equals("nextval", StringComparison.CurrentCultureIgnoreCase) || cr.ToString().Equals("rownum", StringComparison.CurrentCultureIgnoreCase) || cr.ToString().Equals("level", StringComparison.CurrentCultureIgnoreCase)))
			{
				cr.ObjectType = -1;
				return;
			}
			if ((cr.ToString().ToUpper().StartsWith("INSERTED") || cr.ToString().ToUpper().StartsWith("DELETED")) && plocation == ESqlClause.output && this._targetTable != null)
			{
				this._targetTable.ObjectNameReferences.addObjectName(cr);
				return;
			}
			if ((cr.ToString().ToUpper().StartsWith(":NEW") || cr.ToString().ToUpper().StartsWith(":OLD")) && this.TopStatement is TPlsqlCreateTrigger && this.dbvendor == EDbVendor.dbvoracle)
			{
				this.TopStatement.tables.getTable(0).ObjectNameReferences.addObjectName(cr);
				return;
			}
			if (this.locateVariableOrParameter(cr))
			{
				return;
			}
			int num = this.tables.checkColumnReferenceInTables(cr);
			if (num >= 0)
			{
				TTable table = this.tables.getTable(num);
				if (table.BaseTable)
				{
					table.ObjectNameReferences.addObjectName(cr);
					return;
				}
				if (table.CTEName)
				{
					TCTE tcte = this.findCTEByName(table.ToString());
					if (tcte != null)
					{
						TObjectName tobjectName = new TObjectName();
						tobjectName.init(cr.PartToken);
						if (tcte.Subquery != null)
						{
							tcte.Subquery.linkColumnReferenceToTable(tobjectName, plocation);
							return;
						}
					}
				}
				else if (table.TableType == ETableSource.subquery)
				{
					TSelectSqlStatement subquery = table.Subquery;
					if (subquery.ValueClause == null && !subquery.CombinedQuery && subquery.ResultColumnList.size() == 1 && subquery.ResultColumnList.getResultColumn(0).ToString().EndsWith("*", StringComparison.Ordinal))
					{
						bool flag2 = false;
						if (this.GSharpSqlParser.MetaDatabase != null)
						{
							for (int i = 0; i < subquery.tables.size(); i++)
							{
								if (subquery.tables.getTable(i).TableType != ETableSource.subquery)
								{
									string column = null;
									if (cr.PartToken != null)
									{
										column = cr.PartToken.ToString();
									}
									if (subquery.tables.getTable(i).TableName != null && this.GSharpSqlParser.MetaDatabase.checkColumn(subquery.tables.getTable(i).TableName.ServerString, subquery.tables.getTable(i).TableName.DatabaseString, subquery.tables.getTable(i).TableName.SchemaString, subquery.tables.getTable(i).Name, column))
									{
										subquery.tables.getTable(i).ObjectNameReferences.addObjectName(cr);
										flag2 = true;
										break;
									}
								}
							}
						}
						if (!flag2)
						{
							if (subquery.tables.size() > 1)
							{
								cr.TableDetermined = false;
							}
							for (int j = 0; j < subquery.tables.size(); j++)
							{
								subquery.tables.getTable(j).ObjectNameReferences.addObjectName(cr);
							}
							return;
						}
					}
				}
			}
			else if (num == -2)
			{
				bool flag3 = false;
				for (int k = 0; k < this.tables.size(); k++)
				{
					if (this.tables.getTable(k).CTEName && this.tables.getTable(k).CteColomnReferences != null && this.tables.getTable(k).CteColomnReferences.searchColumnReference(cr) >= 0)
					{
						this.tables.getTable(k).ObjectNameReferences.addObjectName(cr);
						flag3 = true;
						break;
					}
				}
				if (!flag3 && cr.Location != ESqlClause.resultColumn && cr.Location != ESqlClause.selectList && cr.Location != ESqlClause.insertColumn && cr.Location != ESqlClause.mergeInsert)
				{
					TCustomSqlStatement parentStmt = this.ParentStmt;
					while (parentStmt != null && parentStmt.sqlstatementtype == ESqlStatementType.sstselect)
					{
						for (int l = 0; l < parentStmt.tables.size(); l++)
						{
							TTable table2 = parentStmt.tables.getTable(l);
							if (table2.TableType == ETableSource.objectname)
							{
								for (int m = 0; m < table2.ObjectNameReferences.size(); m++)
								{
									if (table2.ObjectNameReferences.getObjectName(m).TableDetermined && cr.ToString().Equals(table2.ObjectNameReferences.getObjectName(m).ToString(), StringComparison.CurrentCultureIgnoreCase))
									{
										flag3 = true;
										break;
									}
								}
								if (flag3)
								{
									break;
								}
							}
						}
						if (flag3)
						{
							break;
						}
						parentStmt = parentStmt.ParentStmt;
					}
				}
				if (!flag3)
				{
					flag3 = this.checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt(cr, plocation == ESqlClause.resultColumn || plocation == ESqlClause.selectList || plocation == ESqlClause.mergeInsert || plocation == ESqlClause.insertColumn);
				}
				if (!flag3 && this.tables.size() > 0)
				{
					int num2 = 0;
					int num3 = -1;
					for (int n = 0; n < this.tables.size(); n++)
					{
						if ((!this.tables.getTable(n).CTEName || (this.tables.getTable(n).CTEName && this.tables.getTable(n).CteColomnReferences == null)) && this.tables.getTable(n).TableType != ETableSource.subquery)
						{
							num2++;
							if (num3 == -1)
							{
								num3 = n;
							}
							if (this.GSharpSqlParser.MetaDatabase == null || this.tables.getTable(n).TableName == null)
							{
								this.tables.getTable(n).ObjectNameReferences.addObjectName(cr);
								if (this.tables.size() > 1)
								{
									cr.TableDetermined = false;
								}
								flag3 = true;
								break;
							}
							if (this.GSharpSqlParser.MetaDatabase.checkColumn(this.tables.getTable(n).TableName.ServerString, this.tables.getTable(n).TableName.DatabaseString, this.tables.getTable(n).TableName.SchemaString, this.tables.getTable(n).Name, cr.ToString()))
							{
								this.tables.getTable(n).ObjectNameReferences.addObjectName(cr);
								flag3 = true;
								break;
							}
						}
					}
					if (!flag3 && num2 == 1)
					{
						this.tables.getTable(num3).ObjectNameReferences.addObjectName(cr);
						return;
					}
				}
			}
			else if (num == -1)
			{
				for (TCustomSqlStatement parentStmt2 = this.ParentStmt; parentStmt2 != null; parentStmt2 = parentStmt2.ParentStmt)
				{
					num = parentStmt2.tables.checkColumnReferenceInTables(cr);
					if (num >= 0)
					{
						parentStmt2.tables.getTable(num).ObjectNameReferences.addObjectName(cr);
						return;
					}
				}
			}
		}

		// Token: 0x0600008E RID: 142 RVA: 0x00006838 File Offset: 0x00004A38
		public virtual bool checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt(TObjectName crf, bool sameLevelOnly)
		{
			bool flag = false;
			TCustomSqlStatement tcustomSqlStatement = this;
			while (tcustomSqlStatement != null)
			{
				for (int i = 0; i < tcustomSqlStatement.tables.size(); i++)
				{
					TTable table = tcustomSqlStatement.tables.getTable(i);
					if (table.TableType == ETableSource.subquery)
					{
						flag = this.isColumnNameInSelectList(crf.ToString(), table.Subquery);
						if (flag)
						{
							break;
						}
					}
				}
				if (flag)
				{
					break;
				}
				if (sameLevelOnly)
				{
					tcustomSqlStatement = null;
				}
				else
				{
					tcustomSqlStatement = tcustomSqlStatement.ParentStmt;
				}
			}
			return flag;
		}

		// Token: 0x0600008F RID: 143 RVA: 0x000068A4 File Offset: 0x00004AA4
		private bool isColumnNameInSelectList(string pColumn, TSelectSqlStatement pSelect)
		{
			bool flag = false;
			if (pSelect.CombinedQuery)
			{
				flag = this.isColumnNameInSelectList(pColumn, pSelect.LeftStmt);
				if (!flag)
				{
					flag = this.isColumnNameInSelectList(pColumn, pSelect.RightStmt);
				}
			}
			else if (pSelect.ResultColumnList != null)
			{
				for (int i = 0; i < pSelect.ResultColumnList.size(); i++)
				{
					TResultColumn resultColumn = pSelect.ResultColumnList.getResultColumn(i);
					if (resultColumn.AliasClause != null)
					{
						flag = pColumn.Equals(resultColumn.AliasClause.ToString(), StringComparison.CurrentCultureIgnoreCase);
					}
					if (flag)
					{
						break;
					}
					flag = pColumn.Equals(resultColumn.Expr.ToString(), StringComparison.CurrentCultureIgnoreCase);
					if (flag)
					{
						break;
					}
				}
			}
			return flag;
		}

		// Token: 0x17000015 RID: 21
		// (get) Token: 0x06000090 RID: 144 RVA: 0x0000693C File Offset: 0x00004B3C
		public virtual TCustomSqlStatement TopStatement
		{
			get
			{
				TCustomSqlStatement tcustomSqlStatement = this;
				while (tcustomSqlStatement.ParentStmt != null)
				{
					tcustomSqlStatement = tcustomSqlStatement.ParentStmt;
				}
				return tcustomSqlStatement;
			}
		}

		// Token: 0x04000DC8 RID: 3528
		private string _oracleHint;

		// Token: 0x04000DC9 RID: 3529
		private string _hint;

		// Token: 0x04000DCA RID: 3530
		private List<TObjectName> _DatabaseObjects = new List<TObjectName>();

		// Token: 0x04000DCB RID: 3531
		private TObjectName _labelName;

		// Token: 0x04000DCC RID: 3532
		private TObjectName _endlabelName;

		// Token: 0x04000DCD RID: 3533
		public ESqlStatementType sqlstatementtype;

		// Token: 0x04000DCE RID: 3534
		public TSourceTokenList sourcetokenlist;

		// Token: 0x04000DCF RID: 3535
		public TCustomParser parser;

		// Token: 0x04000DD0 RID: 3536
		public TCustomParser plsqlparser;

		// Token: 0x04000DD1 RID: 3537
		public int stmtDummyTag;

		// Token: 0x04000DD2 RID: 3538
		private TTable _targetTable;

		// Token: 0x04000DD3 RID: 3539
		public TJoinList joins;

		// Token: 0x04000DD4 RID: 3540
		public TTableList tables;

		// Token: 0x04000DD5 RID: 3541
		private TStatementList _statements;

		// Token: 0x04000DD6 RID: 3542
		private TCTEList _cteList;

		// Token: 0x04000DD7 RID: 3543
		private TResultColumnList _resultColumnList;

		// Token: 0x04000DD8 RID: 3544
		private TWhereClause _whereClause;

		// Token: 0x04000DD9 RID: 3545
		private TTopClause _topClause;

		// Token: 0x04000DDA RID: 3546
		private TOutputClause _outputClause;

		// Token: 0x04000DDB RID: 3547
		private TReturningClause _returningClause;

		// Token: 0x04000DDC RID: 3548
		private bool _alreadyAddToParent;

		// Token: 0x04000DDD RID: 3549
		private TCustomSqlStatement _ancestorStmt;

		// Token: 0x04000DDE RID: 3550
		private TCustomSqlStatement _parentStmt;

		// Token: 0x04000DDF RID: 3551
		public TParseTreeNode rootNode;

		// Token: 0x04000DE0 RID: 3552
		private Stack _symbolTable;

		// Token: 0x04000DE1 RID: 3553
		internal TSourceToken semicolonended;

		// Token: 0x04000DE2 RID: 3554
		internal bool isctequery;

		// Token: 0x04000DE3 RID: 3555
		internal ArrayList fsyntaxerrors;

		// Token: 0x04000DE4 RID: 3556
		protected internal bool isparsed;

		// Token: 0x04000DE5 RID: 3557
		internal TSourceToken _semicolon;

		// Token: 0x04000DE6 RID: 3558
		private TObjectNameList _orphanColumns;
	}
}
